package org.example.spring.controller.Admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.spring.domain.dto.FlowerDTO;
import org.example.spring.domain.pojo.Result;
import org.example.spring.domain.pojo.Flower;
import org.example.spring.service.FlowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController("adminFlowerController")
@RequestMapping("/admin/flower")
@Api(tags= "花卉相关接口")
public class FlowerController {

    @Autowired
    private FlowerService flowerService;



    @ApiOperation(value = "获取所有花卉")
    @GetMapping("/getAllFlower") //获取所有花卉
    public Result<ArrayList<Flower>> getAllFlower(){
        ArrayList<Flower> flowers = flowerService.getAllFlower();
        return Result.success(flowers);
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/getFlowerByPage") //分页查询
    public Result<FlowerDTO> getFlowerByPage(FlowerDTO flowerPageDTO){
        ArrayList<Flower> flowers = flowerService.getPageFlower(flowerPageDTO);
        int total = flowerService.getTotalFlower(flowerPageDTO);
        FlowerDTO flowersDTO = new FlowerDTO();
        flowersDTO.setFlowers(flowers);
        flowersDTO.setTotal(total);
        return Result.success(flowersDTO);
    }

    @ApiOperation(value = "根据ID删除花卉")
    @DeleteMapping("/deleteFlowerById") //根据ID删除花卉
    public Result deleteFlowerById(@RequestParam Integer id){
        flowerService.deleteFlowerById(id);
        return Result.success("删除成功");
    }

    @ApiOperation(value = "修改花卉的销售状态")
    @PostMapping("/updateFlowerStatus") //修改花卉的销售状态
    public Result updateFlowerStatus(@RequestBody Flower flower){
        flowerService.updateFlower(flower);
        return Result.success("修改成功");
    }

    @ApiOperation(value = "更新花卉信息")
    @PostMapping("/updateFlower") //更新花卉信息
    public Result updateFlower(@RequestBody Flower flower){
        flowerService.updateFlower(flower);
        return Result.success("修改成功");
    }

    @ApiOperation(value = "添加花卉")
    @PostMapping("/addFlower") //添加花卉
    public Result addFlower(@RequestBody Flower flower){
        flowerService.addFlower(flower);
        return Result.success("添加成功");
    }



}
